**This do-file extracts election dates from Parlgov

import excel using "$project_path/data/1_input/elections/PARLGOV/PARLGOV_Main.xlsx", sheet("election") firstrow clear

// Excluding elections for the European Parliament 
keep if election_type=="parliament"

// Keeping one observation per election
keep country_name election_date
ren country_name Country
duplicates drop 

// Creating year and month variables
gen Year=substr(election_date,1,strpos(election_date,"-")-1)
destring Year, replace
gen Month = substr(election_date,6,2)
destring Month, replace
bysort Country Year: gen temp = _N
replace Month = . if temp == 1
drop temp

// Standardizing country names
replace Country="Czech Rep."  if Country=="Czech Republic"
replace Country="FRG/Germany"  if Country=="Germany"
replace Country="UK"  if Country=="United Kingdom"

// Adjusting month variable
replace Month = 3 if Country == "Sweden" & Year==1914 & Month==4
replace Month = 4 if Country == "Iceland" & Year==1991

// Adjusting format of date variable
gen Date=date( election_date, "YMD")
format Date %td
drop election_date

gen Type_Election="Parliamentary"

keep if Year>1945

sort Type_Election Country Year Month Date
order Country Year Month Type_Election Date
format Country %20s
compress

save "$project_path/data/2_intermediary/elections/Election dates/dates_parlgov.dta", replace
